<?php
$obHanghoadvngay = $this->rsHanghoadvngay;
$obHanghoadvngay = $obHanghoadvngay[0];
//var_dump($obHanghoadvngay);
?>
<header class="panel-heading">
	<strong> Danh Mục Hàng Hóa Dịch Vụ </strong>
</header>

<div class="panel-body">
	<div class="adv-table editable-table ">
		<div class="clearfix">
			<form id="frmaddHanghoadvngay" class="form-horizontal tasi-form" method="get">
			  	<input type="hidden" name="idHanghoadvngay" id="idHanghoadvngay" value="-1" />			  	
				<div class="form-group">
					<label class="col-sm-2 control-label">Ngày</label>
					<div class="col-sm-10">
						<input name="ngay" id="ngay" type="text" class="form-control" data-mask="99/99/9999" placeholder="" value="<?php echo date('d/m/Y')?>" />
						<span class="help-inline">ngày/tháng/năm</span>
					</div>
				</div>
								
				<div class="form-group" id="grpNhomHang">
					<label class="col-sm-2 control-label">Nhóm hàng</label>
					<div class="col-sm-10">                                          
                         <select class="form-control m-bot15" name = "NhomHang" id ="NhomHang">
                                 <option value = "-1"> Chọn nhóm hàng.. </option>
                                 <?php foreach ($this->rsNhomhhdv as $nhomhhdv){?>
                                 	<option value = "<?php echo $nhomhhdv['Id']?>"> <?php echo $nhomhhdv['Ten']?></option>
                                 <?php  }?>
                                 </select>                                          
                    </div>                   
				</div>		
				
				<div class="form-group" id="groupHanghoa">
					<label class = "col-sm-2 control-label">Hàng Hóa</label>
					<div class="col-sm-10">
						<table id="editable-sample" class="table table-striped table-hover table-bordered dataTable" aria-describedby="editable-sample_info">
							<thead>
								<tr role="row">		
									<th class="sorting_disabled" style="width: 50px;"> Chọn	</th>						
									<th class="sorting_disabled" role="columnheader" rowspan="1" colspan="1" style="width: 168px;" aria-label="Username">Tên Hàng</th>
									<th class="sorting_disabled" role="columnheader" rowspan="1" colspan="1" style="width: 168px;" aria-label="Username">Số Lượng</th>																		
								</tr>
		  					</thead>
		  
							<tbody role="alert" aria-live="polite" aria-relevant="all">
								 <?php 
									$stt = 0;
									foreach($this->rsHanghoadv as $rs) { 
									$stt++;
								?>
								<tr>
									<td class="sorting_1"> <input type="checkbox" name="lstHanghoa[]" value="<?php echo $rs['Id'] ?>"/> </td>				  			
									<td class="sorting_1" name ="Ten"><?php echo $rs['Ten'] ?></td>					  								 			  
									<td style="text-align: center" class="center"> <input type = "text" name ="soluong_<?php echo $rs['Id'] ?>" /> </td>				  						  				
								</tr>
								<?php } ?>
							</tbody>
						</table>
					</div>				
				</div>
				
				<div class="form-group">
					<label class="col-sm-2 col-sm-2 control-label">Trạng thái</label>
					<div class="col-sm-10">
						<input name="TrangThai" type="checkbox" checked="" data-toggle="switch" />
					</div>
				</div>
			</form>
			  <div class="modal-footer">
			  	<button data-dismiss="modal" class="btn btn-default" type="button">Đóng</button>
			  	<button class="btn btn-success" type="button" id="luuthaydoi">Lưu thay đổi</button>
			  	<button class="btn btn-success" type="button">Lưu & Thêm mới</button>
		  	  </div>
		</div>
	</div>
</div>
<script>
jQuery(document).ready(function() {
	  
	$("#NhomHang" ).change(function() {
		var getUrl = "<?php echo _BASE_URL?>/quantri/hanghoadvngay";
		var formData = {filter: 'Nhomhang', IdNhomhang : $("#NhomHang").val() };
			
		$.ajax({
			url : getUrl,
			type: "POST",	
			data: formData,
			
			success: function(data, textStatus, jqXHR)
			{
				//alert("Đã lưu thành công!");
			},
			error: function (jqXHR, textStatus, errorThrown)
			{
				//alert('That bai');
			}
		});
	});
	  
	  
	  
	  
	  jQuery("#luuthaydoi").click(function(){

		  var values = $('#frmaddHanghoadvngay').serialize();
		  var saveUrl = "<?php echo _BASE_URL?>quantri/hanghoadvngay/save";
		  //var oTable = $('#editable-sample').dataTable();
		  
		  if($('#ngay').val()=="")
		  {
			alert('Vui lòng nhập ngày.'); 
			return;
		  }
		  
		  $.ajax({
			  url : saveUrl,
			  type: "POST",			
			  data: values,
			  success: function(data, textStatus, jqXHR)
			  {
				  alert("Đã lưu thành công!");
				  location.href= "<?php echo _BASE_URL?>quantri/hanghoadvngay";
			  },
			  error: function (jqXHR, textStatus, errorThrown)
			  {
				  alert('That bai');
			  }
	
			});
	  });
});

</script>